/**
  * @desc to lower case req params
*/
const _ = require('lodash')

const lowerCaseRequestParams = keys => (req, res, next) => {
  const keysToLowerCase = [].concat(keys)
  keysToLowerCase.forEach((key) => {
    const value = _.get(req, key)
    if (typeof value === 'string') {
      // _.set(object, path, value)
      _.set(req, key, value.toLowerCase())
    }
  })
  return next()
}

module.exports = lowerCaseRequestParams
